package com.scst.controller.user;

import com.scst.dto.PageQueryDTO;
import com.scst.dto.WrongAddDTO;
import com.scst.dto.WrongTopicDTO;
import com.scst.result.PageResult;
import com.scst.result.Result;
import com.scst.service.ReportService;
import com.scst.service.WrongService;
import com.scst.vo.TopicReportVo;
import com.scst.vo.WrongAddVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;

@RestController
@Slf4j
@Api("错题")
public class WrongController {
    @Autowired
    WrongService wrongService;
    @Autowired
    ReportService reportService;
    @ApiOperation("科目错题分页查询")
    @GetMapping("/page")
    public Result<PageResult> page(@RequestBody PageQueryDTO pageQueryDTO){
        PageResult pageResult=wrongService.pageQuery(pageQueryDTO);
        return Result.success();
    }
    @ApiOperation("生成错题")
    @PostMapping("/generate")
    public Result<WrongAddVO> generate(@RequestBody WrongAddDTO wrongAddDTO){
        WrongAddVO wrongAddVO=wrongService.generatetopic(wrongAddDTO);
        return Result.success(wrongAddVO);
    }
    @PostMapping()
    @ApiOperation("修改错题")
    public Result update(@RequestBody WrongTopicDTO wrongTopicDTO){
        wrongService.updateWrong(wrongTopicDTO);
        return Result.success();
    }
    @GetMapping("topicStatistics")
    @ApiOperation("语文统计")
    public Result<TopicReportVo> topicReportVoResult(
            @DateTimeFormat(pattern="yyyy-MM-dd")
            LocalDate begin,
            @DateTimeFormat(pattern="yyyy-MM-dd")
            LocalDate end) {
        return Result.success(reportService.getTopicStatistics(begin,end));
    }
    @GetMapping("/")
    @ApiOperation("数学统计")
    public Result<TopicReportVo> MathStatistics(
            @DateTimeFormat(pattern="yyyy-MM-dd")
            LocalDate begin,
            @DateTimeFormat(pattern="yyyy-MM-dd")
            LocalDate end) {
        return Result.success(reportService.getMathTopicStatistics(begin,end));
    }
}
